import {
    fetchData
} from '@/utils';

/**
 * @description: 带有默认参数 appkey 的请求
 * @param {*} url
 * @param {*} type
 * @param {*} params
 * @return {*}
 */
async function fetchInsideData(url, type, params = {}) {
    let appkey = 'bobo_1621138855071';
    params = {
        appkey,
        ...params
    }
    return await fetchData(url, type, params);
}

/**
 * 获取产品分类列表
 * @param {*} type 请求方式
 * @param {*} params 传递的数据
 */
export async function getCateList(params) {
    return await fetchInsideData('/category/all', 'get', params);
}

/*** 
 * @description: 获取产品列表
 * @param {*} params
 * @return {*}
 */
export async function getGoodsList(params) {
    return await fetchInsideData('/products/all', 'get', params);
}

/*** 
 * @description: 删除指定 id 的产品
 * @param {*} params
 * @return {*}
 */
export async function deleteGoods(params) {
    let id = params.id;
    return await fetchInsideData(`/products/${id}`, 'delete', {});
}

/**
 * @description: 上传图片
 * @param {*} params
 * @return {*}
 */
export async function uploadImage(params) {
    return await fetchInsideData(`/upload/images`, 'post', params);
}

/*** 
 * @description: 添加产品
 * @param {*} params
 * @return {*}
 */
export async function addGoods(params){
    return await fetchInsideData(`/products/add`, 'post', params);
}

/*** 
 * @description: 根据 id 值来获取产品的详细信息
 * @param {*} params
 * @return {*}
 */
export async function getGoodInfo(params){
    return await fetchInsideData('/products/'+params.id,'get');
}

/*** 
 * @description: 修改的产品的数据
 * @param {*} params
 * @return {*}
 */
export async function editGoodInfo(params){
    return await fetchInsideData('/products/edit','put',params);
}